/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ru.vsu.cs.piit.vokod.TableModels;

import java.util.Date;
import javax.swing.table.AbstractTableModel;
import ru.vsu.cs.piit.vokod.IListListener;
import ru.vsu.cs.piit.vokod.ObservableArrayList;
import ru.vsu.cs.piit.vokod.Utils;
import ru.vsu.cs.piit.vokod.model.Pacient;

/**
 *
 * @author Галчонок
 */
public class PacientsTableModel  extends AbstractTableModel {

    ObservableArrayList<Pacient> rows;
    Pacient tmp;

    public PacientsTableModel(ObservableArrayList<Pacient> list) {
        rows = list;
        list.AddListener(new IListListener() {

            public void doSave(Object object) {
                fireTableDataChanged();
            }

            public void doRemove(Object object) {
                fireTableDataChanged();
            }
        });
    }

    public int getRowCount() {
        return rows.size();
    }

    public int getColumnCount() {
        return 17;
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex)
        {
            case 0:
                return rows.get(rowIndex).getDateOfComing();
            case 1:
                return rows.get(rowIndex).getDateOfDischarge();
            case 2:
                return rows.get(rowIndex).getWard();
            case 3:
                return rows.get(rowIndex).getFio();
            case 4:
                return rows.get(rowIndex).getDiagnos();
            case 5:
                if (rows.get(rowIndex).getDiagnos()!=null)
                    return rows.get(rowIndex).getDiagnos().getGroupOfDiagnos();
                else
                    return null;
            case 6:
                return rows.get(rowIndex).getBeddays();
            case 7:
                return Utils.getDays(rows.get(rowIndex).getDateOfComing(), rows.get(rowIndex).getDateOfDischarge());
            case 8:
                return rows.get(rowIndex).getComplex();
            case 9:
                return rows.get(rowIndex).getTreatment();
            case 10:
                if (rows.get(rowIndex).getTreatment()!=null)
                    return rows.get(rowIndex).getTreatment().getGroupOfTreatment();
                else return null;
            case 11:
                return rows.get(rowIndex).getDaysBeforeTreatment();
            case 12:
                return rows.get(rowIndex).getMoveFrom();
            case 13:
                return rows.get(rowIndex).getMoveTo();
            case 14:
                return rows.get(rowIndex).getDateOfEntry();
            case 15:
                return rows.get(rowIndex).getDateOfCorrect();
            case 16:
                return rows.get(rowIndex).getDied();
        }
        return null;
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        switch (columnIndex)
        {
            case 0:
            case 1:
            case 14:
            case 15:
                return Date.class;
            case 8:
            case 16:
                return Boolean.class;
        }
        return super.getColumnClass(columnIndex);
    }

    @Override
    public String getColumnName(int column) {
        switch (column)
        {
            case 0:
                return "Дата поступления";
            case 1:
                return "Дата выбытия";
            case 2:
                return "Отделение";
            case 3:
                return "ФИО";
            case 4:
                return "Диагноз";
            case 5:
                return "Группа диагноза";
            case 6:
                return "К/д";
            case 7:
                return "К/д 2";
            case 8:
                return "Компл.";
            case 9:
                return "Вид лечения";
            case 10:
                return "Группа вида лечения";
            case 11:
                return "К/д до нач.леч.";
            case 12:
                return "Переведен из";
            case 13:
                return "Переведен в";
            case 14:
                return "Дата ввода";
            case 15:
                return "Дата корректировки";
            case 16:
                return "Умер";
        }
        return null;
    }

    public void delRow(int i)
    {
        rows.remove(rows.get(i));
    }

    public Pacient getPacient(int i)
    {
        return rows.get(i);
    }
}

